{{Extend "layout"}}
{{Block "title"}}{{if HasSuffix URL.Path "/add"}}{{"添加任务"|T}}{{else}}{{"修改任务"|T}}{{end}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="/task/index">{{"任务列表"|T}}</a></li>
<li class="active">{{if HasSuffix URL.Path "/add"}}{{"添加任务"|T}}{{else}}{{"修改任务"|T}}{{end}}</li>
{{/Block}}
{{Block "main"}}

{{$addingMode:=HasSuffix URL.Path "/add"}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat">
          <div class="header">							
            <h3>{{if $addingMode}}{{"添加任务"|T}}{{else}}{{"修改任务"|T}}{{end}}</h3>
          </div>
          <div class="content">
              <form class="form-horizontal group-border-dashed" method="POST" action="">
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"任务名称"|T}}</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="name" required value="{{Form "name"}}">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"任务说明"|T}}</label>
                <div class="col-sm-8">
                    <textarea class="form-control" name="description">{{Form "description"}}</textarea>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"分组"|T}}</label>
                <div class="col-sm-8">
                  {{$v := Form "groupId"}}
                    <select class="form-control" name="groupId">
                      <option value="">{{"未分组"|T}}</option>
                     {{range $k,$g:=Stored.Get "groupList"}}
                     <option value="{{$g.Id}}"{{if eq $v (Str $g.Id)}} selected{{end}}>{{$g.Name}}</option>
                     {{end}}
                    </select>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"执行时间"|T}}</label>
                <div class="col-sm-8">
                  <div class="input-group">
                    <span class="input-group-addon">{{"秒"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="秒，有效范围为0-59的整数。可出现'*'、'/'、','、'-'四个字符" required name="seconds" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-5]?[0-9]([/-][0-5]?[0-9])?"}}" value="{{Form "seconds"}}">
                    <span class="input-group-addon">{{"分"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="分，有效范围为0-59的整数。可出现'*'、'/'、','、'-'四个字符" required name="minutes" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-5]?[0-9]([/-][0-5]?[0-9])?"}}" value="{{Form "minutes"}}">
                    <span class="input-group-addon">{{"时"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="小时，有效范围为0-23的整数。可出现'*'、'/'、','、'-'四个字符" required name="hours" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-2]?[0-9]([/-][0-2]?[0-9])?"}}" value="{{Form "hours"}}">
                    <span class="input-group-addon">{{"日"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="日，有效范围为1-31的整数。可出现'*'、'/'、','、'-'、'?'五个字符" required name="dayOfMonth" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-3]?[0-9]([/-][0-3]?[0-9])?" "?"}}" value="{{Form "dayOfMonth"}}">
                    <span class="input-group-addon">{{"月"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="月，有效范围为1-12的整数。可出现'*'、'/'、','、'-'四个字符" required name="month" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-1]?[0-9]([/-][0-1]?[0-9])?"}}" value="{{Form "month"}}">
                    <span class="input-group-addon">{{"周"|T}}:</span>
                    <input type="text" class="form-control" data-toggle="tooltip" title="周，有效范围为0-6的整数，0代表星期天。可出现'*'、'/'、','、'-'、'?'五个字符" required name="dayOfWeek" onfocus="onfocusInput(this)" pattern="{{buildPattern "[0-6]([/-][0-6])?" "?"}}" value="{{Form "dayOfWeek"}}">
                  </div>
                  <!--<input type="text" class="form-control" required name="cronSpec" value="{{Form "cronSpec"}}">-->
                  <div class="help-block">
                    特定字符的含义如下：
			<ul>
				<li><code><a href="javascript:;" onclick="insertAtCursor(this)">*</a></code> 表示匹配该域的任意值，假如在Minutes域使用*, 即表示每分钟都会触发事件。</li>
				<li><code><a href="javascript:;" onclick="insertAtCursor(this)">?</a></code> 字符仅被用于“日”和“周”两个子表达式，表示不指定值，当两个子表达式其中之一被指定了值以后，为了避免冲突，需要将另一个子表达式的值设为“?”。</li>
				<li><code><a href="javascript:;" onclick="insertAtCursor(this)">-</a></code> 表示范围，例如在Minutes域使用5-20，表示从5分到20分每分钟触发一次。</li>
				<li><code><a href="javascript:;" onclick="insertAtCursor(this)">/</a></code> 表示起始时间开始触发，然后每隔固定时间触发一次，例如在Minutes域使用5/20,则意味着在5分的时候开始触发一次，而25，45等分别触发一次。</li>
				<li><code><a href="javascript:;" onclick="insertAtCursor(this)">,</a></code> 表示列出枚举值。例如：在Minutes域使用5,20，则意味着在5和20分每分钟触发一次。</li>
			</ul>
                  </div>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"执行命令"|T}}</label>
                <div class="col-sm-8">
                  <textarea class="form-control" name="command" required>{{Form "command"}}</textarea>
                  <div class="help-block">{{"命令"|T}}</div>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"超时时间"|T}}</label>
                <div class="col-sm-8">
                  <div class="input-group">
                  <input type="number" class="form-control" name="timeout" value="{{Form "timeout"}}" min="0">
                  <span class="input-group-addon">{{"秒"|T}}</span>
                  </div><div class="help-block">{{"默认为86400(1天)"|T}}</div>
                </div>
              </div>
              
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"多实例"|T}}</label>
                <div class="col-sm-8">
                  {{$v := Form "concurrent"}}
                  <label class="radio-inline">
                      <input type="radio" value="0" name="concurrent"{{if or (eq $v "0") (eq $v "")}} checked{{end}}> {{"否"|T}}
                  </label>
                  <label class="radio-inline">
                      <input type="radio" value="1" name="concurrent"{{if eq $v "1"}} checked{{end}}> {{"是"|T}}
                  </label>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"通知邮件"|T}}</label>
                <div class="col-sm-8">
                  {{$v := Form "enableNotify"}}
                  <label class="radio-inline">
                      <input type="radio" value="0" name="enableNotify" {{if or (eq $v "0") (eq $v "")}} checked{{end}} onclick="$('#cc-email-addr').addClass('hidden')"> {{"不通知"|T}}
                    </label>
                    <label class="radio-inline">
                      <input type="radio" value="1" name="enableNotify" {{if eq $v "1"}} checked{{end}} onclick="$('#cc-email-addr').removeClass('hidden')"> {{"执行结束时通知"|T}}
                    </label>
                    <label class="radio-inline">
                      <input type="radio" value="2" name="enableNotify" {{if eq $v "2"}} checked{{end}} onclick="$('#cc-email-addr').removeClass('hidden')"> {{"执行失败时通知"|T}}
                    </label>
                </div>
              </div>
              <div class="form-group{{if or (eq $v "0") (eq $v "")}} hidden{{end}}" id="cc-email-addr">
                <label class="col-sm-2 control-label">{{"通知邮件抄送"|T}}</label>
                <div class="col-sm-8">
                  <textarea class="form-control" name="notifyEmail">{{Form "notifyEmail"}}</textarea>
                  <div class="help-block">{{"每行一个Email地址"|T}}</div>
                </div>
              </div>
              
              <div class="form-group">
									<div class="col-sm-9 col-sm-offset-2">
									  <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> {{"保存"|T}}</button>
									  <button type="reset" class="btn btn-default btn-lg"><i class="fa fa-refresh"></i> {{"重置"|T}}</button>
									</div>
							</div>
            </form>
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
    </div>
</div>
{{/Block}}
{{Block "footer"}}
<script type="text/javascript">
var currentFocusInput;
function insertAtCursor(obj){
  if(!currentFocusInput)return;
  App.insertAtCursor(currentFocusInput,$(obj).text());
}
function onfocusInput(obj){
  currentFocusInput=obj;
}
</script>
{{/Block}}